let UserTasksDao = require("../dao/userTasksDao")
let JsonMessage = require("../models/JsonMessage")
module.exports = {

    selectUserTodayTasks: function (req, res) {

        UserTasksDao.selectUserTodayTasks(req.session.userid).then((results) => {
            if (results.length > 0) {
                res.json(new JsonMessage("1110", results, "User Today Tasks"))
            } else {
                res.json(new JsonMessage("4110", results, "No User Today Tasks"))
            }
        })

    },
    selectUserTodayTasksTimeEsc: function (req, res) {

        UserTasksDao.selectUserTodayTasksTimeEsc(req.session.userid).then((results) => {
            if (results.length > 0) {
                res.json(new JsonMessage("1110", results, "User Today Tasks"))
            } else {
                res.json(new JsonMessage("4110", results, "No User Today Tasks"))
            }
        })

    }  ,
    selectTommorrowTasks: function (req, res) {
        UserTasksDao.selectUserTomorrowTasks(req.session.userid).then((results) => {
            if (results.length > 0) {
                res.json(new JsonMessage("1004", results, "无明日任务"))
            } else {
                res.json(new JsonMessage("1005", null, "无明日任务"))
            }
        })
    },
    selectUserTodayTasksTimeDesc: function (req, res) {

        UserTasksDao.selectUserTodayTasksTimeDesc(req.session.userid).then((results) => {
            if (results.length > 0) {
                res.json(new JsonMessage("1110", results, "User Today Tasks"))
            } else {
                res.json(new JsonMessage("4110", results, "No User Today Tasks"))
            }
        })

    }
    ,
    submitTask: function (req, res) {
        let userid = req.session.userid;
        let taskid = req.body.taskid
        let submit_description = req.body.submit_description;
        let date = Math.round(new Date().getTime()/1000)

        UserTasksDao.updateUserTasks(userid,taskid,submit_description,1,date).then((results) => {
            if (results.length > 0) {
                res.json(new JsonMessage("1110", results, "User Today Tasks"))
            } else {
                res.json(new JsonMessage("4110", results, "No User Today Tasks"))
            }
        })

    }
    ,
    selectUserTommorrowTasks: function (req, res) {

        UserTasksDao.selectUserTodayTasks(req.session.userid).then((results) => {
            if (results.length > 0) {
                res.json(new JsonMessage("1110", results, "User Tomorrow Tasks"))
            }else {
                res.json(new JsonMessage("4111", results, "No User Tomorrow Tasks"))
            }

        })
    },
    selectUserTomorrowTasksEscTime: function (req, res) {


        UserTasksDao.selectUserTomorrowTasksEscTime(req.session.userid).then((results) => {
            if (results.length > 0) {
                res.json(new JsonMessage("1110", results, "User Tomorrow Tasks"))
            }else {
                res.json(new JsonMessage("4111", results, "No User Tomorrow Tasks"))
            }

        })
    },
    selectUserTomorrowTasksDescTime: function (req, res) {

        UserTasksDao.selectUserTomorrowTasksDescTime(req.session.userid).then((results) => {
            if (results.length > 0) {
                res.json(new JsonMessage("1110", results, "User Tomorrow Tasks"))
            }else {
                res.json(new JsonMessage("4111", results, "No User Tomorrow Tasks"))
            }

        })
    }




}